<template>
    <Navtitle :titles="title"></Navtitle>
    <van-row>
        <van-col span="6">
            <van-sidebar v-model="active" @change="onChange">
                <van-sidebar-item v-for="item in categoriesApiData" :title="item.cat_name" />
            </van-sidebar>
        </van-col>
        <van-col span="18">
            <van-skeleton title :row="20" animate v-if="showSkeleton" />
            <div v-else>
                <div v-for="item in categoriesApiData[active]?.children">
                    <h5>{{ item.cat_name }}</h5>
                    <router-link :to="{ name: 'goods', params: { query: item.cat_name } }">
                        <van-grid :column-num="4">
                            <van-grid-item v-for="items in item.children" :icon="items.cat_icon"
                                :text="item.cat_name" />
                        </van-grid>
                    </router-link>
                </div>
            </div>
        </van-col>
    </van-row>
</template>

<script setup>
let showSkeleton=ref(true)
import { categoriesApi } from '@/api/api';
import Navtitle from '@/components/Navtitle.vue';
import { ref } from 'vue';
const title = '分类页'
let categoriesApiData = ref([])
categoriesApi().then(res => {
    categoriesApiData.value = res.data.message
})
const onChange=()=>{
    showSkeleton.value=true
    setTimeout(()=>{
        showSkeleton.value=false
    },2000)
}
onChange()
const active = ref(0)
</script>

<style lang="scss" scoped></style>